package com.aaa.controller.yy;


import com.aaa.pojo.ResultBean;
import com.aaa.pojo.yy.PlanSds;

import com.aaa.service.yy.PlanSdsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/planSds")

public class PlanSdsController {

    @Autowired

    private PlanSdsService planSdsService;
    ResultBean resultBean = new ResultBean();
    @RequestMapping("/pagination")
    public ResultBean quSds(String page, String limit){
        int count = planSdsService.findCount();
        List<PlanSds> all = planSdsService.findAllPlan(page, limit);


        resultBean.setCode(0);
        resultBean.setMsg("");
        resultBean.setCount(count);
        resultBean.setData(all);
        return  resultBean;

    }

    @RequestMapping("/insert")
    public ResultBean planSdsInsert(PlanSds planSds){
        planSds.setTestCode((int)((Math.random()*9+1)*100000));
        planSds.setCreateTime(new Date());
        System.out.println(planSds);
        int insert = planSdsService.insert(planSds);
        resultBean.setCode(0);
        resultBean.setMsg("");
        resultBean.setCount(insert);
        resultBean.setData(planSds);
        return  resultBean;
    }

    @RequestMapping("/update")
    public ResultBean quSdsUpdate(PlanSds planSds){
        //System.out.println(quSds);
        int update = planSdsService.update(planSds);
        ResultBean resultBean = new ResultBean();
        resultBean.setCode(0);
        resultBean.setMsg("");
        resultBean.setData(planSds);
        resultBean.setCount(update);
        //String s = JSON.toJSONString(resultBean);
        return resultBean;
    }


    @RequestMapping("/delete")
    public ResultBean quSdsDelete(@RequestParam("idList") List<String> idList){
        //System.out.println(quSds);
        int delete = planSdsService.delete(idList);
        ResultBean resultBean = new ResultBean();
        resultBean.setCode(0);
        resultBean.setMsg("");
        //String s = JSON.toJSONString(resultBean);
        return resultBean;
    }

    @RequestMapping("/planFuzzyQuestionAndCreatBy")
    public ResultBean quSdsUpdate( String testName,String createBy){
        //System.out.println(quSds);
        int count = planSdsService.findCount();

        List<PlanSds> planSds = planSdsService.planFuzzyQuestionAndCreatBy(testName, createBy);
        System.out.println(planSds);
        ResultBean resultBean = new ResultBean();
        resultBean.setCode(0);
        resultBean.setMsg("");
        resultBean.setData(planSds);
        resultBean.setCount(count);
        //String s = JSON.toJSONString(resultBean);
        return resultBean;
    }

}
